cmake_minimum_required(VERSION 3.19)
set(MAHONY_6_AXIS "6-axis mahony")
set(INS "INS")
set(MAHONY_9_AXIS "9-axis mahony")


if(DEFINED FUSION_ENGINE)
    set(CMAKE_FUSION_ENGINE ${FUSION_ENGINE})
    message("The fusion algorithm is ${CMAKE_FUSION_ENGINE}")
else()
#    set(CMAKE_FUSION_ENGIN ${INS})
    message(FATAL_ERROR "The fusion algorithm is not set")
endif()

if(CMAKE_FUSION_ENGINE STREQUAL  ${MAHONY_6_AXIS})
    message(STATUS "Configure for ${CMAKE_FUSION_ENGINE}")
    add_compile_options(-DFUSION_ENGINE_MAHONY_6_AXIS)
    include_directories(Mahony)
    file(GLOB FUSION_ENGIN_SOURCE
            ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/App/algorithm/SensorFusion.c
            ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/App/algorithm/Mahony/MahonyAHRS.c
            )

elseif(CMAKE_FUSION_ENGINE STREQUAL  ${MAHONY_9_AXIS})
    message(STATUS "${CMAKE_FUSION_ENGIN} is not supported")
elseif(CMAKE_FUSION_ENGINE STREQUAL ${INS})
    message(STATUS "Configure for ${CMAKE_FUSION_ENGINE}")
    add_compile_options(-DFUSION_ENGINE_INS)
    set(RGIOE_DIR  ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/App/algorithm/RGIOE)
    include_directories(${RGIOE_DIR}/Inc)
    message(CHECK_START "Finding Eigen")
    set(Eigen3_DIR ${RGIOE_DIR}/Lib/eigen)
    find_package(Eigen3 CONFIG)
    message(CHECK_PASS "found")
    include_directories(${EIGEN3_INCLUDE_DIR})

    file(GLOB FUSION_ENGIN_SOURCE
            ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/App/algorithm/SensorFusion.c
            ${RGIOE_DIR}/Src/*.cpp
            )

else()
    message(FATAL_ERROR "Unknown Fusion Engine or the Engine is not supported, so no Fusion Engine configured!!!")
endif()

